//
//  ProfileEditContentView.swift
//  App_Profile
//
//  Created by 蒋晨成 on 2022/1/18.
//

import Adaptor
import RxCocoa
import RxSwift
import UICore
import UIKit

class ProfileEditContentView: UIScrollView {
    private lazy var contentView: UIView = .init()
        .x
        .backgroundColor(Adaptor.Profile.background)
        .instance

    lazy var signoutButton: UIButton = .init(type: .custom)
        .x
        .setTitle(ProfileModular.localizedString(key: "Profile.Setting.Button.Signout.Title"), for: .normal)
        .setTitleColor(Adaptor.Profile.subtitleColor, for: .normal)
        .border(color: Adaptor.Profile.subtitleColor, width: 1.0)
        .corners(radius: 24)
        .instance

    lazy var listView: RYCollectionContentView = {
        let listView = RYCollectionContentView()
        return listView
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        contentInsetAdjustmentBehavior = .never
        alwaysBounceVertical = true
        setupUI()
    }

    @available(*, unavailable)
    required init?(coder _: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

private extension ProfileEditContentView {
    func setupUI() {
        contentView.x.add(to: self)

        contentView.snp.makeConstraints {
            $0.edges.equalToSuperview()
            $0.width.equalToSuperview()
            $0.height.equalToSuperview()
        }

        signoutButton.x.add(to: contentView).snp.makeConstraints {
            $0.leading.equalTo(20)
            $0.trailing.equalTo(-20)
            $0.height.equalTo(48)
            $0.bottom.equalTo(contentView).offset(-Adaptor.KeyWindow.safeAreaBottom - 20)
        }

        listView.x.add(to: contentView).snp.makeConstraints {
            $0.top.equalToSuperview()
            $0.trailing.leading.equalToSuperview()
            $0.bottom.equalTo(signoutButton.snp.top).offset(-20)
        }
    }
}
